#!/bin/bash

# This file is part of the SHACrypt test suite and is licensed
# under the same license as SHACrypt.

# Description:
# Make a file with a null byte, then 1024 random bytes. Attempt
# to encrypt it with the password "test", do an asymmetric crypt
# handshake to change the password to "tset" (test backwards)
# and then decrypt it with the password "tset"

echo "Test 4: Real asymmetric crypt"

./test-helper rand4.tmp

$SHACRYPT e test rand4.tmp f4a.tmp
$SHACRYPT a tset f4a.tmp f4b.tmp
$SHACRYPT a test f4b.tmp f4a.tmp
$SHACRYPT d tset f4a.tmp f4b.tmp
result=$?

if [[ "$result" != "0" ]]
then cmp -s rand4.tmp f4b.tmp
	result=$?
fi

rm -f rand4.tmp f4a.tmp f4b.tmp

exit $result